home *** CD-ROM | disk | FTP | other *** search
- Path: druid.borland.com!usenet
- From: pete@borland.com (Pete Becker)
- Newsgroups: comp.lang.c++
- Subject: Re: const's and Borland C++
- Date: 17 Feb 1996 23:05:34 GMT
- Organization: Borland International
- Distribution: world
- Message-ID: <4g5mvu$m25@druid.borland.com>
- References: <4g2gu8$hpe@enst.enst.fr>
- NNTP-Posting-Host: pbecker.borland.com
- Mime-Version: 1.0
- Content-Type: Text/Plain; charset=ISO-8859-1
- X-Newsreader: WinVN 0.99.5
-
- In article <4g2gu8$hpe@enst.enst.fr>, orfanos@ima.enst.fr says...
- >
- >
- >Hello,
- >
- >What's going here on with float const's and Borland C++ 4.5?
- >
- > --- MAGWEG.H ---
- > const float FOO1 = 23.0;
- > const float FOO2 = -62.33;
- >
- > --- MAGWEG.CPP ---
- > #include "magweg.h"
- >
- > int main()
- > {
- > float f = FOO1;
- > f /= 2;
- >
- > return 0;
- > }
- >
- > --- compiler messages ---
- > Compiling MAGWEG.CPP:
- > Warning MAGWEG.H 1: Cannot create pre-compiled header:
- > initialized data in header
- > Warning MAGWEG.CPP 11: 'FOO2' is declared but never used
- > Linking magweg.exe:
- >
- >The first warning should not be emitted, because I disabled
- >it in Options|Project|Messages|General.
-
-
- >The second warning should never be emitted.
-
- Why not? You defined a data object and did not use it, as the warning said.
- Note that a const declaration is not like a #define. It says "I want a data
- object of this type", so the compiler created one.
-
- > In fact, it appears
- >only with float const's, not with int const's!
-
- Yup. The compiler usually doesn't generate any storage for definitions of
- const integral types, because it can put them in registers. Can't do that with
- floating point types, so there has to be an object somewhere.
- -- Pete
-
-